package com.car.action.api;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.car.common.model.Tags;
import com.car.common.model.Topics;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jfinal.core.Controller;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.IDataLoader;
import com.utils.APIJSON;
import com.utils.StringUtil;

public class TagController extends Controller{

	public void get_user_tags() {
        Map<String,Object> tag1 = Maps.newHashMap();
        tag1.put("id", 1);
        tag1.put("name", "我是什么样子的人");
        List<Map<String,Object>> data1 = Lists.newArrayList();
        List<Tags> dataList1 = Tags.dao.find("select id,name,parent_id from tags where parent_id = 1 order by sort desc ");
        for(Tags one : dataList1) {
        	Map<String,Object> temp = Maps.newHashMap();
        	temp.put("id", one.get("id"));
        	temp.put("name", one.get("name"));
        	temp.put("parent_id", one.get("parent_id"));
        	data1.add(temp);
        }
        tag1.put("child", data1);
        
        Map<String,Object> tag2 = Maps.newHashMap();
        tag2.put("id", 2);
        tag2.put("name", "我想要找什么样子的人");
        List<Map<String,Object>> data2 = Lists.newArrayList();
        List<Tags> dataList2 = Tags.dao.find("select id,name,parent_id from tags where parent_id = 2 order by sort desc ");
        for(Tags one : dataList2) {
        	Map<String,Object> temp = Maps.newHashMap();
        	temp.put("id", one.get("id"));
        	temp.put("name", one.get("name"));
        	temp.put("parent_id", one.get("parent_id"));
        	data2.add(temp);
        }
        tag2.put("child", data2);
        
        ArrayList<Map<String,Object>> result = Lists.newArrayList();
        
        result.add(tag1);
        result.add(tag2);
        renderText(APIJSON.send(result));
	}
	
	public void get_card_tags() {
		ArrayList<Map<String,Object>> topicList = CacheKit.get("constant", "topicList", new IDataLoader(){
		       public Object load() {
		           return Topics.dao.getAll();
		}});
		renderText(APIJSON.send(topicList));	
	}
	
	public void get_private_tags() {
		List<Map<String,Object>> data3 = Lists.newArrayList();
	    List<Tags> dataList3 = Tags.dao.find("select id,name,parent_id from tags where parent_id = 3 order by sort desc ");
        for(Tags one : dataList3) {
        	Map<String,Object> temp = Maps.newHashMap();
        	temp.put("id", one.get("id"));
        	temp.put("name", one.get("name"));
        	temp.put("parent_id", one.get("parent_id"));
        	data3.add(temp);
        }
		renderText(APIJSON.send(data3));
	}
	
}
